package com.adingxiong.cft.config;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @ClassName MinioProperties
 * @Description TODO
 * @Author xiongchao
 * @Date 2021/1/21 10:12
 **/
@Data
@ConfigurationProperties(prefix="minio",ignoreInvalidFields = true)
@Slf4j
public class MinioProperties implements InitializingBean {

    private String endpoint;

    private String accessKey;

    private String secretKey;

    private String httpUrl;

    private Long imgSize;

    private Long fileSize;

    private List<String> fileType;

    @Override
    public void afterPropertiesSet() throws Exception {
        if(StringUtils.isEmpty(getEndpoint())){
            throw new IllegalStateException("Property \"minio.endpoint\" cannot  be blank");
        }
        if(StrUtil.isEmpty(getAccessKey())){
            throw new IllegalStateException("Property \"minio.accessKey\" cannot  be blank");
        }
        if(StrUtil.isEmpty(getSecretKey())){
            throw new IllegalStateException("Property \"minio.secretKey\" cannot  be blank");
        }
        log.info("文件上传的格式有:{}",getFileType().toString());
    }
}
